package tag;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.jsp.JspException;

import toolkit.Debug;
import bean.PizzaBean;
import domain.value.Ingredient;

public class IngredientsTag extends AbstractTag
{
	PizzaBean pizza;
	
	@SuppressWarnings("unchecked")
	@Override
	public int doStartTag() throws JspException
	{
		String body = "<ul>";
		
		for (Ingredient ingredient: (ArrayList<Ingredient>) pizza.get("ingredients"))
		{
			body += "<li>" + ingredient.toString() + "</li>";
		}
		
		body += "</ul>";
		
		try
		{
			pageContext.getOut().print(body);
		}
		catch (IOException e)
		{
			Debug.log(e);
		}
		
		return EVAL_PAGE;
	}
	
	public void setBean(PizzaBean bean)
	{
		Debug.log("(" + id + ") IngredientsTag.setBean(" + bean + ")");
		
		pizza = bean;
	}
	
}
